/*
"JSFXGEN" - Pin.as
Modular Integrated Development Environment for JesuSonic
Project page: http://jsfxgen.googlecode.com

Copyright 2009 Lubomir I. Ivanov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package neolit123.jsfxgen
{
  import flash.display.DisplayObject;
  import flash.display.Sprite;
  import flash.display.Graphics;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import neolit123.ui.Box;
  // =========================================================
  public class Pin extends Sprite
  {
    private var bkg:Box;
    private const colorfill:int = 0x000000;
    private const colorborder:int = 0xffffff;
    public var isinput:Boolean;
    public var active:Boolean;
    public var index:int;
    public var parentid:int;
    public var cons:Array = [];
    // =========================================================
    public function Pin(setisinput:Boolean,setx:Number,sety:Number,setindex:int,setparentid:int,setname:String):void
    {
      active = true;
      // @ properties
      isinput = setisinput;
      x = setx;
      y = sety;
      name = setname;
      index = setindex;
      parentid = setparentid;
      // @ set btn
      buttonMode = true;  
      mouseChildren = false;
      bkg = new Box(10,10,colorfill,colorborder);
      addChild(bkg);
      // @ connection source
      addEventListener(MouseEvent.MOUSE_DOWN, startdraw);
      function startdraw(e:Event):void
      {
        if (active) {
          Main.consource = e.target;
          Main.consource.isinput = e.target.isinput;
          Main.consource.parentid = e.target.parentid;
          Main.dodraw = true;
          Main.initX = stage.mouseX-Main.mcd.x;
          Main.initY = stage.mouseY-Main.mcd.y;
        }
      }
      // @ connection destination 
      addEventListener(MouseEvent.MOUSE_UP, enddraw, false, 0, true);
      function enddraw(e:MouseEvent):void
      {
        Main.condest = e.target;
        Main.condest.isinput = e.target.isinput;
        Main.condest.parentid = e.target.parentid;
      }
    }
  }
}